package com.yunfeisoft.business.service.impl;

import com.yunfeisoft.business.dao.inter.ElderHospitalizationDao;
import com.yunfeisoft.business.model.ElderHospitalization;
import com.yunfeisoft.business.service.inter.ElderHospitalizationService;
import com.yunfeisoft.common.base.BaseServiceImpl;
import com.yunfeisoft.common.sql.separation.DataSourceChange;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import sun.net.www.HeaderParser;

import java.util.List;
import java.util.Map;

/**
 * ClassName: ElderHospitalizationServiceImpl
 * Description: 住院治疗情况从表service实现
 * Author: Jackie liu
 * Date: 2020-04-04
 */
@Service("elderHospitalizationService")
public class ElderHospitalizationServiceImpl extends BaseServiceImpl<ElderHospitalization, String, ElderHospitalizationDao> implements ElderHospitalizationService {

    @Override
    @DataSourceChange(slave = true)
    public Page<ElderHospitalization> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    @Override
    public List<ElderHospitalization> getByHealthId(String elderHealthId) {
        return getDao().getByHealthId(elderHealthId);
    }

    @Override
    public void deleteByHealthId(String elderHealthId) {
        getDao().deleteByHealthId(elderHealthId);
    }

    @Transactional
    public void saveHospitalization(List<ElderHospitalization> hospitalizationList) {
        if (!ObjectUtils.isEmpty(hospitalizationList)) {
            // 先删除之前的记录
            getDao().deleteByHealthId(hospitalizationList.get(0).getElderHealthId());
            // 添加新的记录
            for (ElderHospitalization hospitalization : hospitalizationList) {
                getDao().insert(hospitalization);
            }
        }
    }
}